<template>
  <a-cascader v-model:value="id" :options="userList" placeholder="title" @change="confirmUser" :show-search="{ filter }"/>
  
</template>

<script setup name="UserSingle">
import { watch } from "vue";
// import userStore from '../../../../store/user'

const emit = defineEmits(["confirm"]);
const userId = ref({
  userIds: undefined,
});
const userList = ref([]);
const users = ref([]);
const userValue = ref([]);
const props = defineProps({
  title: {
    type: String,
    default: "请选择负责人",
  },
  id: {
    type: Number,
  },
  show: {
    type: Boolean,
  },
});
const filter = (inputValue, path) => {
  return path.some(userList => userList.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
};
watch(
  () => [props.id, props.show],
  ([newValue, newShow], [oldValue, oldShow]) => {
    getUsers();
  }
);

getUsers();
function getUsers() {
  // userStore().userlist.then((res) => {
  //   userList.value = res;
  //   console.log('user-single里的userList',userList.value);
  // });
}

//用户单选
function confirmUser(e) {
  let selectedUser = userList.value
    .find((item) => item.deptId === e[0])
    .children.find((item) => item.id === e[1]);
  emit("confirm", selectedUser);
}
</script>